import { AddOrCahngeCount, CartItem } from "@/type/cartTypes"
import { ResponseType } from "@/type/response"
import request from "@/utils/request"

enum Enum {
  addCartOrCahngeGoodCountAPI = "/cart/addToCart",
  fetchCartListAPI = "/cart/getCartList",
  deleteCartAPI = "/cart/delete",
  changeGoodCheckedAPI = "/cart/checkCart",
  changeGoodAllCheckedAPI = "/cart/checkAllCart"
}
/**
 * @description 加入购物车和修改商品数量的接口
 */
export const addCartOrCahngeGoodCountAPI = (info: AddOrCahngeCount) => {
  return request.get(`${Enum.addCartOrCahngeGoodCountAPI}/${info.goodsId}/${info.count}`, { blessing: info.blessing })
}

/**
 * 
 * @description 获取购物车列表的接口
 */
export const fetchCartListAPI = () => request.get<ResponseType<CartItem[]>>(Enum.fetchCartListAPI)

/**
 * 
 * @description 删除购物车商品的接口
 */
export const deleteCartAPI = (goodsId: number) => request.get<ResponseType<null>>(`${Enum.deleteCartAPI}/${goodsId}`)

/**
 * 
 * @description 修改勾选商品状态的接口
 */
export const changeGoodCheckedAPI = (goodsId: number, isChecked: 0 | 1) => request.get(`${Enum.changeGoodCheckedAPI}/${goodsId}/${isChecked}`)

/**
 *
 * @description 全选和取消全选的接口
 */
export const changeGoodAllCheckedAPI=(isChecked:0|1)=>request.get(`${Enum.changeGoodAllCheckedAPI}/${isChecked}`)